3. enumeratives
在上一课中,我们讨论了这些结构、它们的使用方式以及它们在本视频中的指控期间如何对您有用。
In the last lesson, we talked about the structures, how they are used and how they are useful for you during your allegations in this video.
我们将讨论枚举。
We will talk about enumerations.
枚举是特定用户定义的类型,用于对数据可能具有的一系列可能值进行分类。
Enumerations are a particular user defined that a type that is used to classify a series of possible values that the data may have.
例如,您听说它们以不同的方式非常有用。
For instance, you hear they are quite useful in a different kind of way.
正如您在这里看到的,我们在这里使用这个模型类型变量做了一些小技巧。
As you saw here, we did a little trick over here with this model type variable here.
我们使用一个整数,并在我们之间声明一个代码来说明这个整数变量的实际含义。
We use that an integer, and we declared a code between ourself to say what was actually the meaning of this integer variables.
这就是倡议的目的。
This is what initiatives are for.
例如,这里我们说的0是同步的,1是无刷电机的等等。
For instance, here we are saying that zero is for a synchronous matter, one is for a brushless motors and so on.
但如果我删除此注释,您将不会知道有关此整数值的任何信息。
But if I remove this comment, you wouldn't know anything about this integer value here.
声明一种可以具有一些离散值的变量类型可能很有用。
It could be useful to declare a type of variables that could have some discrete values.
例如,电机类型变量可以是无刷同步电机、步进电机、电机、本电机等。
For instance, a motor type variable that can be a synchronous motor brushless, motor stepper, motor, this motor and so on.
为之服务是多么荣幸。
And this is what an honor to serve for.
声明信息丰富。
To declare an informative.
您只需进入应用程序和对象数据单元类型。
You simply need to go into application and object data unit type.
这里你需要点击枚举。
And here you need to click on enumeration.
在这里我们可以声明一个异常,我们将其称为新的模型类型。
And here we can declare an anomaly that we will call a new model type.
稍后我会解释为什么使用这个前缀。
I will explain later why I use this prefix.
因此,如果我在这里声明它,您将在您的 p.l.c. 中看到另一个对象。
So if I declare it over here, you will see another object in your p.l.c.
配置,你会看到我们已经定义了它。
configuration and you will see that we have defined it.
在这里,我们有一个成员,尽管在这里您需要定义枚举可能具有的所有可能值。
And over here we have a single member, although here you need to define all the possible values that your enumerated may have.
例如,我们正在讨论电机,因此我们可以使用与此处使用的相同的实际分类。
For instance, we are talking about motors, so we may use the same actual classification that we use over here.
因此,如果我在这里删除这个东西,我可以说这个启发的可能值是异步的。
So if I delete this thing over here, I may say that the possible values for this illuminative are asynchronous.
我可以加一个逗号。
I can add a comma.
看,下一个是无刷,下一个是步进。
See, in the next one is brushless, the next one is stepper.
最后一个是BC。
And the last one is B C.
所以在这里,我声明一种类型可以具有可能的值。
So over here, I'm declaring it that a type of can have for possible values.
如果我进入我的 p.l.c.
If I go in my p.l.c.
NPG值,我可以在这里声明。
NPG value, I can declare over here.
看,这是一些电机类型变量,该类型应该是这里的新电机类型。
See, that is some motor type variable and the type shall be a new motor type over here.
我实际上可以将其中一个可能的值分配给主格。
I can actually assign one of these for possible values to the nominative.
这是通过以下方式完成的。
And this is done in the following way.
您需要编写分子的类型和模型类型,然后您以这种方式选择可能性,您实际上正在做与我们之前所做的相同的事情,因为如果您看一下实际的说明,这就是字节码一个整数值,一个仅具有一些允许值的整数值。
You need to write the type of the numerator and model type that and you select the possibility in this way you are actually doing the same thing that we were doing before, because if you look beneath the actual illuminative, this is and the bytecode this as an integer value, an integer value that has only some allowed values.
但通过这种方式,您可以在代码中实际放置变量的实际含义。
But in this way you are able to actually place in the code the actual meaning of your variable.
因此,通过这种方式,如果我们回到我们的元数据结构,对不起,我要关闭一些东西而不是使用军事类型,我们可能会说这是敌人,对不起,敌人迫击炮类型。
So in this way, if we go back to our metadata structure, sorry, I'm closing a few things instead of using a military type, we may say that this is an enemy sorry, enemy mortar type.
如果我现在上网并下载。
And if I go online right now and I download.
在这里您将看到,在 mortar 类型下,您有一个 Synchronoss 值,也就是说,这不是一个字符串,这只是我们在这里使用的值的表示。
Here you will see that under mortar type, you have as a value as Synchronoss, that is this is not a string, this is simply a representation of the values that we are using here.
正如我所说,这是作为整数值处理的,所以你总是可以在这里,你总是可以说实际值是什么,与枚举值相对应的整数值?
And as I said, that this is handled as an integer value, so you could always had that over here, you can always say what is the actual value, integer value corresponding to the enumerated value?
所以我说一个Synchronoss等于0无刷等于1步等于2,而这个C等于3,就像我之前做的那样。
So I me say that a Synchronoss is equal to zero brushless is equal to one step is equal to two, and this C is equal to three, as I did before.
因此,当我走到这里时,我可以在任何情况下看到该类型等于枚举模型类型,点异步。
So when I go over here, I can see in any situation that the type is equal to enum model type, dot asynchronous.
在这里我需要一个新的模型类型来说明这一点。
And here I will need a new model type that lets say this.
如果我进行下载。
And if I carry out to download.
你可以在这里看到,当 this 被视为一个常量值时,你可以在海边看到它,在这里靠近变量值,如果我按开始,这意味着零。
You can see over here when the this is treated as a constant value, you can see this by the sea and over here near the value of the variable, and this means zero if I press start.
正如你所看到的,这已经变得等同于大海了。
As you can see, this has become equals to the sea.
这意味着它代表的实际值等于三。
That means that it represents the real value equal to three.
动机对于以更优雅和结构化的方式表示配置数据非常有用,它非常有用。
And the motives are quite useful to represent, uh, configuration data in a more elegant and structured way, it is quite useful.
在本课程中,我们将使用生命相当长的一段时间。
We will use lives for quite a while during this course.
我们只想看看这里的一些事情。
And also we just want to look at the few things over here.
当你声明时,你就拥有了这两个属性。
Here you have when you declare and then you have this two attributes.
属性是 Cotsis,因为这个工件用于将特征的某些特性实际应用到某个对象。
Attributes are Cotsis, because this artifact that is used to actually apply some characteristics of features to a certain object.
因此有很多属性,它们用于库和研究和开发的一些相当高级的编程。
So there are many attributes and they are used for some quite advanced programming for libraries and research and development.
但在这里你会看到这两个是自动声明的。
But over here you will see this two that are declared automatically.
它们是什么意思?
And what do they mean?
严格意味着如果您实际上想要为任何新模型类型变量分配一个值,则需要指定。
Strict means that you if you want to actually, um, assign a value to any new model type variable, you need to specify.
实际上你不能也不能只分配任何数值。
You cannot actually and you cannot assign just any numeric value.
您需要以这种方式分配它们。
You need to assign assign them in this way.
这意味着新的多元宇宙只能具有这四个值。
It means that a new multiverse can only have these four values.
因此,如果我在这里编写而不是同步覆盖模式或等于三的类型并进行编译,您可以看到没有错误。
So if I go over here and write instead of a synchronous overwrite mode or type equal to three and I compile, you can see that there is no error.
但相反,如果我写五个,这是规范所不允许的。
But instead, if I write five, that is not allowed by the normative.
您将看到这会导致编译器错误,指出 5 不是枚举脚本的有效值。
You will see that this leads to a compiler error saying that five is not a valid value for the script enumerated.
如果我在这里删除 strict 属性并执行构建,您将看到现在没有公司错误。
And if I remove the strict attribute over here and I carry out a build, you will see that right now there are no compay errors.
因此,如果我在这里再次打直,我建议还有其他一些事情要始终保留连胜以重视此属性。
So if I play straight again here, there are other things I suggested to always leave the streak to value this attribute.
当你使用枚举数和限定数时,只有更多,呃,你实际上可以选择删除它,因为在这里你需要当我们定义时,我们抱歉,为枚举赋值,我们看到 Monotype 是相等的在我们指定的异步模型类型中,它是它来自的枚举。
When you are using enumerators and the qualified, only instead is quite more, uh, you can actually choose to remove it because here you need to when we define when we sorry, assign a value to the enumerated, we are seeing that Monotype is equal to in the model type that asynchronous we are specifying, which is the enumerated that it is coming from.
如果你去掉了限定,就只有你可以写了。
If you remove the qualified, only you are able to you write instead.
Monotype 等同于 Synchronoss,但不指定这一点。
Monotype is equal to a Synchronoss without specifying this one.
所以在这里,您可以看到我们没有编译器错误,如果我再次请您放心,您会看到编译器说编译器实际上并不知道异步意味着什么。
So over here, you can see that we have no compiler error, and if I please the confidence again that you will see a compiler saying that the compiler is not actually doesn't actually know what asynchronous means.
好吧,如果您在项目中使用了很多很多启发性内容,也许只保留限定内容是很有意义的,因为您可能会将一个信息的价值分配给另一个信息。
Well, if you're using many, many illuminative in your projects, maybe maintaining the qualified only is makes a lot of sense because you may be assigning the value of an informative to another.
因此,举例来说,如果我们必须枚举具有异步值的其他值,但对于一个异步意味着零,对于另一个异步意味着三。
So, for instance, if we have to enumerate the others that have the value asynchronous, but for one asynchronous means zero and out for another one, asynchronous means three.
你可能会犯一些错误,但如果你只使用一些叙述,你也可以删除它,如果你简单地编写更多类型等于异步和,它可能会让你的代码更容易阅读这种方式更容易实际检测到实际读取这里发生的事情。
You may have a some make some mistakes over there, but if instead you are using just a few narrative's, you may as well remove it and it may make your code more easy to read if you simply write more type is equal to a asynchronous and this way is quite easier to actually detect to actually read what is happening over here.
这实际上取决于你。
It is actually up to you.
我通常只留下合格的,因为我已经习惯了。
I normally leave the qualified only because I'm used to it.
但是,如果,呃,如果这是您第一次使用肺炎,那么您实际上可能需要一段时间才能掌握它们的语法。
But if, uh, if it is this is the first time you're using a pneumonitis, it may actually take a while before you get over the the syntax of them.
我想建议你的一件事通常是生活在规范的、有时非价值等于零的环境中。
And one of the things that I, I want to suggest you typically is to live in the normative sometimes non value equal to zero.
所以只需以这种方式更改枚举器即可。
So simply change the enumerators in this way.
第一个等于零等于无。
The first one equals zero equal to none.
所以你能够真正看到什么时候你没有,嗯,什么时候你没有,嗯,给敌人赋值。
So you are able to actually see when you didn't, um, when you didn't the, um, assign a value to the enemy.
所以就这样。
So in this way.
对不起,我会里贾德。
Sorry, I will Rijad.
在这里我只删除合格的。
Over here I remove the qualified only.
所以我就和之前做一个比较。
So I will make just a comparison from before.
正如您在上线之前所看到的,我们会看到所有分子都等于零,而早期的零意味着异步。
As you saw before we went online, we would have seen all the numerator is equal to zero and earlier zero meant asynchronous.
因此,您会看到每个模型都等于 Synchronoss,并且不确定您是否实际分配了它们,或者它们是否以这种方式等于默认值。
So you are seeing every model equal to Synchronoss and you are not sure if you actually assign them or if they are equal to the default value in this way.
如果我们到这里看到同步,我确信在某个地方值得同步,因为在其他母亲中我们没有看到。
If we go over here and I see a synchronous, I am sure that are worth a Synchronoss somewhere because in the other mothers we see none.
我会看到另一个值,它实际上会告诉我是否在那里分配了值。
I will see another value that actually will actually tell me if I did assign a value there or not.
这是,呃,一个简单的,呃,让我们说,规则,呃,for,呃,使用枚举,呃,可能对您在,呃,不同类型的操作和,呃,编程任务中派上用场。
This is, uh, a simple, uh, let's say, rule, uh, for, uh, using renumerated that, uh, may come in handy for you in, uh, in different kinds of operations and, uh, and programming tasks.
因此,我们稍后会在许多不同的应用程序中看到异常情况。
So we will later on see anomalies in many different applications.
所以请继续关注该项目。
So stay tuned in the project.
所以我们实际上会明白为什么它们在编程时很有用。
So we will actually see why they are useful when programming.